package com.sea.example.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * Description: 返回web实体
 * Author: hcxu
 * Time: 2024/9/5 3:24 PM
 */
@Data
public class ApiResponse<T> implements Serializable {
    private static final long serialVersionUID = 1605750667850382560L;
    private Integer code;

    private String msg;

    private T data;

    private ApiResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private ApiResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ApiResponse<T> success(T data){
        return new ApiResponse<>(200, "", data);
    }

    public static <T> ApiResponse<T> success(T data, int code, String msg){
        return new ApiResponse<>(code, msg, data);
    }

    public static <T> ApiResponse<T> error(T data){
        return new ApiResponse<>(503, "", data);
    }

    public static <T> ApiResponse<T> error(Integer code, String msg){
        return new ApiResponse<>(code, msg);
    }
}
